package com.itsq.controller.resources;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itsq.common.base.BaseController;
import com.itsq.common.bean.ErrorEnum;
import com.itsq.common.bean.Response;
import com.itsq.pojo.dto.PageUsersDto;
import com.itsq.pojo.dto.PageViolationDto;
import com.itsq.pojo.entity.Car;
import com.itsq.pojo.entity.Users;
import com.itsq.pojo.entity.Violation;
import com.itsq.service.resources.ViolationService;
import com.itsq.token.CurrentUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 史先帅
 * @since 2021-02-01
 */
@RestController
@RequestMapping("/violation")
@AllArgsConstructor
@CrossOrigin
@Api(tags = "违章信息模块")
public class ViolationController  extends BaseController {

    @Autowired
    private ViolationService violationService;

    @PostMapping("selViolationPageFront")
    @ApiOperation(value = "违章信息模块前台分页查询", notes = "", httpMethod = "POST")
    public Response<Page<Violation>> selViolationPageFront(@RequestBody PageViolationDto pageViolationDto){
        Page<Violation> ViolationPage = violationService.selViolationPageFront(pageViolationDto);
        return Response.success(ViolationPage);
    }

    @PostMapping("selViolationPageAfter")
    @ApiOperation(value = "管理员——违章信息模块后台分页查询", notes = "", httpMethod = "POST")
    public Response<Page<Violation>> selViolationPageAfter(@RequestBody PageViolationDto pageViolationDto){
        CurrentUser currentUser = currentUser();
        if(currentUser==null){
            return Response.fail(ErrorEnum.SIGN_VERIFI_EXPIRE);
        }
        Page<Violation> ViolationPage = violationService.selViolationPageAfter(pageViolationDto);
        return Response.success(ViolationPage);
    }

    @ResponseBody
    @RequestMapping(value = "/findwz", method = RequestMethod.POST)
    public String findwz(Integer id){
        return violationService.findwz(id);
    }

    @PostMapping("insert")
    @ApiOperation(value = "违章信息模块手动添加信息", notes = "", httpMethod = "POST")
    public Response<Integer> insert(@RequestBody Violation violation){
        return Response.success(violationService.insert(violation));
    }

    @PostMapping("update")
    @ApiOperation(value = "违章信息模块手动修改信息", notes = "", httpMethod = "POST")
    public Response<Integer> update(@RequestBody Violation violation){
        return Response.success(violationService.update(violation));
    }

    @PostMapping("delete")
    @ApiOperation(value = "违章信息模块手动修改信息", notes = "", httpMethod = "POST")
    public Response<Integer> delete(Integer id){
        return Response.success(violationService.delete(id));
    }
}

